package com.zenghus.v2.mapper;

import com.zenghus.v2.sqlsession.SqlSession;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import static com.zenghus.v2.mapper.MapperRegistory.mothodsqlMapper;

public class MapperProxy<T> implements InvocationHandler{
    private SqlSession sqlsession;

    public MapperProxy(SqlSession sqlsession) {
        this.sqlsession=sqlsession;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MapperRegistory.MapperDate mapperDate=
                sqlsession.configuration.getMapperRegistory()
                        .mothodsqlMapper
                        .get(method.getDeclaringClass().getName() + "." + method.getName());
        return sqlsession.selectOne(mapperDate,args);
    }
}
